package com.zaizai.controller;

import java.util.List;

import com.zaizai.domain.AjaxResult;
import com.zaizai.utils.ExcelUtil;
import com.zaizai.utils.page.TableDataInfo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zaizai.domain.Log;
import com.zaizai.service.ILogService;

import static com.zaizai.domain.AjaxResult.success;

/**
 * 操作日志Controller
 *
 * @author zaiZai
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/log")
public class LogController extends BaseController {
    @Autowired
    private ILogService logService;

    /**
     * 查询操作日志列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Log log) {
        startPage();
        List<Log> list = logService.selectLogList(log);
        return getDataTable(list);
    }

    /**
     * 导出日志信息
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, Log log) {
        List<Log> list = logService.selectLogList(log);
        ExcelUtil<Log> util = new ExcelUtil<Log>(Log.class);
        util.exportEasyExcel(response, list, "操作日志数据");
    }
    /**
     * 新增操作日志
     */
    @PostMapping
    public AjaxResult add(@RequestBody Log log) {
        return success(logService.insertLog(log));
    }

    /**
     * 删除操作日志
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return success(logService.deleteLogByIds(ids));
    }
}
